import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		isLogin: false, //是否登录
		userInfo: {
			userId: '', //用户ID
			nickName: '', //用户昵称
			userTele: '', //用户账号
			avatar: '', //用户头像
			userSex: '', //用户性别
			memberType: '', //认证类型
			tokenName: '',
			tokenValue: '',
			userScore: 0
		},
		appVersion:'1.0.0',
		shareId: ''
	},
	mutations: {
		setShareId(state, shareId) {
			state.shareId = shareId;
		},
		setAppVersion(state, appVersion) {
			state.appVersion = appVersion;
		},
		setUserId(state, userId) {
			state.userInfo.userId = userId;
		},
		setNickName(state, nickName) {
			state.userInfo.nickName = nickName;
		},
		setUserTele(state, userTele) {
			state.userInfo.userTele = userTele;
		},
		setAvatar(state, avatar) {
			state.userInfo.avatar = avatar;
		},
		setUserSex(state, userSex) {
			state.userInfo.userSex = sex;
		},
		setMemberType(state, memberType) {
			state.userInfo.memberType = memberType;
		},
		setIsLogin(state, isLogin) {
			state.isLogin = isLogin;
		},
		setTokenName(state, tokenName) {
			state.userInfo.tokenName = tokenName;
		},
		setTokenValue(state, tokenValue) {
			state.userInfo.tokenValue = tokenValue;
		},
		setUserScore(state, userScore) {
			state.userInfo.userScore = userScore;
		},
		setUserInfo(state, data) {
			state.isLogin = true
			if (data.id) {
				state.userInfo.userId = data.id
			}
			if (data.nickName) {
				state.userInfo.nickName = data.nickName
			}
			if (data.tele) {
				state.userInfo.userTele = data.tele
			}
			if (data.avatar) {
				state.userInfo.avatar = data.avatar
			}
			if (data.sex) {
				state.userInfo.userSex = data.sex
			}
			if (data.memberType) {
				state.userInfo.memberType = data.memberType
			}
			if (data.tokenName) {
				state.userInfo.tokenName = data.tokenName
			}
			if (data.tokenValue) {
				state.userInfo.tokenValue = data.tokenValue
			}
			if (data.userScore) {
				state.userInfo.userScore = data.userScore
			}
		},
		setLogout(state, value) {
			state.isLogin = false
			state.userInfo.userId = ''
			state.userInfo.nickName = ''
			state.userInfo.userTele = ''
			state.userInfo.avatar = ''
			state.userInfo.userSex = ''
			state.userInfo.memberType = ''
			state.userInfo.tokenName = ''
			state.userInfo.tokenValue = ''
			state.userInfo.userScore = 0
		}
	},
	actions: {

	},
	getters: {
		getShareId(state, getters) {
			return state.shareId
		},
		getAppVersion(state, getters) {
			return state.appVersion
		},
		getUserInfo(state, getters) {
			return state.userInfo
		},
		getUserId(state, getters) {
			return state.userInfo.userId
		},
		getNickName(state, getters) {
			return state.userInfo.nickName
		},
		getUserTele(state, getters) {
			return state.userInfo.userTele
		},
		getAvatar(state, getters) {
			return state.userInfo.avatar
		},
		getUserSex(state, getters) {
			return state.userInfo.userSex
		},
		getMemberType(state, getters) {
			return state.userInfo.memberType
		},
		getIsLogin(state, getters) {
			return state.isLogin
		},
		getTokenName(state, getters) {
			return state.userInfo.tokenName
		},
		getTokenValue(state, getters) {
			return state.userInfo.tokenValue
		},
		getUserScore(state, getters) {
			return state.userInfo.userScore
		},

	}
})
export default store